export default {
	//提交
	submit() {
		// this.form.state = this.form.state ?  this.form.state : 0;
		if (this.id == undefined) {

			this.add();
		} else {
			this.edit();
		}
	},

	getRole(info) {
		if(info) {
			this.id = info.id;
			this.form = info;
			this.form.state = this.form.state.toString();
		}
		
		
		var parms = {
			page: 1,
			limit: 0
		}

		this.axiosGets("Role/getAllRole", parms, function(res) {

			this.role = res.data.data.data
			//分页
			// this.total=res.data.data.total
		})
	},

	closeDialog() {
		this.isShow = false;
		this.form = {
			username: "", //	fgdfg	必填	用户名
			password: "", //	fghgfh33	必填	密码
			password_confirm: "", //	fghgfh33	必填	确认密码
			realname: "", //	asdas	必填	姓名
			state: 0, //	1	必填	状态 0 禁用 1 启用
			role_ids: ''
		}
	},


	//添加
	add() {
		let para = {
			admin: this.form
		}
		console.log(this.select.sign);
		this.axiosPost("Admin/add", para.admin, function(data) {
			if (data.data.code == 1) {
				this.msgSuccess(data.data.message);
				this.$parent.getTableData()
				// this.history("/admin")
			} else {
				this.msgError(data.data.message)
			}
			this.closeDialog()
		}, this.select.sign)

		// this.getSelect();
	},

	//编辑
	edit() {
		delete this.form.role_name
		let para = {
			admin: this.form
		}
		this.axiosPost("Admin/editor?id=" + this.id, para.admin, function(data) {
			if (data.data.code == 1) {
				this.msgSuccess(data.data.message);
				this.$parent.getTableData()
				// this.history("/admin")
			} else {
				this.msgError(data.data.message)
			}
			this.closeDialog()
		}, this.select.sign)

		// this.getSelect();
	},

	//初始化
	init() {
		let para = {
			id: this.id
		}
		this.axiosGets("Admin/editor", para, function(data) {
			if (data.data.code == 1) {
				this.dataShow(data.data.data);
			} else {
				this.history("/admin")
			}
		})
	},

	//数据显示
	dataShow(data) {
		this.form = {
			username: data.username, //	fgdfg	必填	用户名
			realname: data.realname, //	asdas	必填	姓名
			state: data.state + "", //	1	必填	状态 0 禁用 1 启用
		}
	},

	//获取选择项
	// getSelect() {
	//   this.axiosGets("admin/add", {}, function(data) {
	//     this.select.sign = data.data.data;
	//   })
	// }
}
